<?php

/**
 * MyProjectNameHere <http://www.example.com>
 * Model Class
 *
 * It is recommended to extend Model classes from WWW_Factory in order to 
 * provide various useful functions and API access for the Model.
 *
 * @package    Factory
 * @author     DeveloperNameHere <email@example.com>
 * @copyright  Copyright (c) 2012, ProjectOwnerNameHere
 * @license    Unrestricted
 * @tutorial   /doc/pages/guide_mvc.htm
 * @since      1.0.0
 * @version    1.0.0
 */

class WWW_model_religiousplaces extends WWW_Factory {

	/**
	 * It is recommended to define all data variables here. Usually the 
	 * data variables have the same names as the column names of database 
	 * rows from a table.
	 */	
	public $conn;
	/**
	 * Alternative to __construct()
	 *
	 * WWW_Factory does not allow to overwrite __construct() method, so 
	 * this __initialize() is used instead and loaded automatically when 
	 * object is created.
	 *
	 * @return boolean
	 */
	public function __initialize(){
		require('engine/class.www-database.php');
		$this->conn=new WWW_Database();				
		
		require('engine/include_dao.php');
		return true;
		
	}
	public function create_religiousplace($data){
		
		$religiousPlace = new ReligiousPlace();
		$religiousPlace->religiousplaces_name = $data['religiousplaces_name'];
		$religiousPlace->religiousplaces_type = $data['religiousplaces_type'];
		$religiousPlace->religiousplaces_address = $data['religiousplaces_address'];
		$religiousPlace->religiousplaces_url = $data['religiousplaces_url'];
		$religiousPlace->religiousplaces_phone1 = $data['religiousplaces_phone1'];
		$religiousPlace->religiousplaces_phone2 = $data['religiousplaces_phone2'];
		$religiousPlace->created_date = date("Y-m-d h:i:s");
		$religiousPlace->updated_date = date("Y-m-d h:i:s");
		$result = DAOFactory::getReligiousPlacesDAO()->insert($religiousPlace);
		//print_r($result);exit;
			
	/* $query="insert into `religious_places` (religiousplaces_name,religiousplaces_type,religiousplaces_address,religiousplaces_url,religiousplaces_phone1,religiousplaces_phone2,created_date,updated_date) VALUES ('".$data['religiousplaces_name']."','".$data['religiousplaces_type']."','".$data['religiousplaces_address']."','".$data['religiousplaces_url']."','".$data['religiousplaces_phone1']."','".$data['religiousplaces_phone2']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
	$result=$this->conn->dbCommand($query);	 */
		//$this->db->last_query();exit;
	if($result !== 0){
			return array('message'=>'Religious Places successfully created');			
		}else{
			return array('message'=>'Religious Places Creation Failed');
		}	
	}
	public function edit_religiousplace($data){
	
		$religiousPlace = new ReligiousPlace();
		$religiousPlace->religiousplaces_id = $data['religiousplaces_id'];
		$religiousPlace->religiousplaces_name = $data['religiousplaces_name'];
		$religiousPlace->religiousplaces_type = $data['religiousplaces_type'];
		$religiousPlace->religiousplaces_address = $data['religiousplaces_address'];
		$religiousPlace->religiousplaces_url = $data['religiousplaces_url'];
		$religiousPlace->religiousplaces_phone1 = $data['religiousplaces_phone1'];
		$religiousPlace->religiousplaces_phone2 = $data['religiousplaces_phone2'];
		$religiousPlace->status = $data['status'];
		$religiousPlace->updated_date = date("Y-m-d h:i:s");
		$result = DAOFactory::getReligiousPlacesDAO()->update($religiousPlace);
		//print_r($result);exit;
	/* $query="update `religious_places` set religiousplaces_name='".$data['religiousplaces_name']."',religiousplaces_type='".$data['religiousplaces_type']."',religiousplaces_address='".$data['religiousplaces_address']."',religiousplaces_url='".$data['religiousplaces_url']."',religiousplaces_phone1='".$data['religiousplaces_phone1']."',religiousplaces_phone2='".$data['religiousplaces_phone2']."',updated_date='".date("Y-m-d H:i:s")."' where religiousplaces_id=".$data['religiousplaces_id'];
		$result=$this->conn->dbCommand($query); */		
		if($result !== 0){
			return array('message'=>'Religious Places Updated Successfully');			
		}else{
			return array('message'=>'Religious Places Updates Failed');
		}	
	
	}
	public function get_religiousplace($data)
	{	
		$religiousPlace = new ReligiousPlace();
		$religiousPlace->religiousplaces_id = $data['religiousplaces_id'];
		$result = DAOFactory::getReligiousPlacesDAO()->load($religiousPlace);
		//print_r($result);exit;
		
		/* $query="SELECT religiousplaces_name,religiousplaces_type,religiousplaces_address,religiousplaces_url,religiousplaces_phone1,religiousplaces_phone2 from religious_places where religiousplaces_id=".$data['religiousplaces_id']; 
		$result=$this->conn->dbMultiple($query);*/
		if($result !== ''){
			return array('message'=>'Religious Places get Successfully', 'result'=>$result);			
		}else{
			return array('message'=>'Religious Places get Failed');
		}	
		
	}
	public function delete_religiousplace($data){
		
		$religiousPlace = new ReligiousPlace();
		$religiousPlace->religiousplaces_id = $data['religiousplaces_id'];
		$religiousPlace->status = $data['status'];
		$result = DAOFactory::getReligiousPlacesDAO()->delete($religiousPlace);
		//print_r($result);exit;
		
		/* $data=$this->conn->dbCommand("update `religious_places` set status='".$data['status']."' where religiousplaces_id=".$data['religiousplaces_id']); */
		if($result !== 0)
			return array('message'=>"Religious Places Deleted Successfully");		
		else
			return array('message'=>'Religious Places Deletion Fails');
	}
	public function all_religiousplace($data){
		$current_page=0;
	$results_per_page=10;
	$order_by="created_date";
	$sort_order="desc";
	if(isset($data['order_by']) && $data['order_by']!='')
	{
		$order_by=$data['order_by'];
	}
	if(isset($data['results_per_page']) && $data['sort_order']!='')
	{
		$sort_order=$data['sort_order'];
	}
	if(isset($data['current_page'])&& $data['current_page']!='' || $data['current_page']!=0)
	{
	$current_page=$data['current_page'];
	}
	if(isset($data['results_per_page']) && $data['results_per_page']!='' || $data['results_per_page']!=0){
	$results_per_page=$data['results_per_page'];
	}
	$offset=$current_page;
	/* $query_sting = "select * from `religious_places`";
	$query_sting1 = "SELECT count(*) as total from religious_places"; */
	if (isset($data['search_by']) && $data['search_by']!='')
	{	//print_r($data);exit;
		if($data['search_by']=='status')
		{	
			$search_by = "status";
			
		}else if($data['search_by'] == 'religiousplaces_type')
		{
			$search_by = "religiousplaces_type";
		}else if($data['search_by'] == 'religiousplaces_name')
		{
			$search_by = "religiousplaces_name";
		}
		else if($data['search_by'] == 'religiousplaces_url')
		{
			$search_by = "religiousplaces_url";
		}

			$religiousPlace = new ReligiousPlace();
			$religiousPlace->order_by = $order_by;
			$religiousPlace->sort_order = $sort_order;
			$religiousPlace->results_per_page = $results_per_page;
			$religiousPlace->offset = $offset;
			$religiousPlace->search_by = $search_by;
			$religiousPlace->search_by_value = $data['search_by_value'];
			$result = DAOFactory::getReligiousPlacesDAO()->queryAllSearchBy($religiousPlace);
			$totalrows = DAOFactory::getReligiousPlacesDAO()->SearchByCount($religiousPlace);
			//print_r($totalrows);exit;
			
			/* $query =  $query_sting." where ".$search_by."='".$data['search_by_value']."' order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
			$query1 = $query_sting1." where ".$search_by."='".$data['search_by_value']."'"; */
	}else
	{
			$religiousPlace = new ReligiousPlace();
			$religiousPlace->order_by = $order_by;
			$religiousPlace->sort_order = $sort_order;
			$religiousPlace->results_per_page = $results_per_page;
			$religiousPlace->offset = $offset;
			$result = DAOFactory::getReligiousPlacesDAO()->queryAll($religiousPlace);
			$totalrows = DAOFactory::getReligiousPlacesDAO()->queryAllCount($religiousPlace);
			//print_r($totalrows);exit;
			
		/* $query = $query_sting." order by ".$order_by." ".$sort_order." limit ".$results_per_page." offset ".$offset;
	$query1 = $query_sting1; */
	}
	//print_r($query);exit;
	//$result=$this->conn->dbMultiple($query);
		if($result !== ''){
			//$totalrows = $this->conn->dbSingle($query1);
		return array('message'=>"All ","info"=>$result,'total'=>$totalrows['total'],'current_page'=>$current_page,'results_per_page'=>$results_per_page);
		}
		else
		return array('message'=>'No Religious Places');
	}
	
}
	
?>